package com.itheima.controller;

import com.itheima.pojo.Address;
import com.itheima.pojo.Result;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 测试响应数据
 */
@RestController
public class ResponseController {

    // 1. 响应字符串
    @RequestMapping("/hello")
    public Result hello() {
        System.out.println("Hello World!");
//        return new Result(1, "success", "Hello World~");
        return Result.success("Hello World~");
    }

    // 2. 响应对象json
    @RequestMapping("/getAddr")
    public Result getAddr() {
        Address addr = new Address();
        addr.setProvince("广东");
        addr.setCity("深圳");
        System.out.println(addr);
        return Result.success(addr);
    }


    @RequestMapping("/listAddr")
    public Result listAddr() {
        List<Address> list = new ArrayList<>();

        Address addr = new Address();
        addr.setProvince("广东");
        addr.setCity("深圳");

        Address addr2 = new Address();
        addr2.setProvince("北京");
        addr2.setCity("北京");

        list.add(addr);
        list.add(addr2);
        System.out.println(list);
        return Result.success(list);
    }

}
